package com.ruoyi.web.utils;

import com.ruoyi.common.exception.base.BaseException;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;

public class UtilsSetting {
    /**
     * 获取开始时间以及截止时间
     *
     * @Auth: 张恒
     */
    public static HashMap<String, Date> getDate(Date date) {
        HashMap<String, Date> hashMap = new HashMap<>();
        try {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            String format1 = dateFormat.format(date);
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date beginDate = format.parse(format1 + " 00:00:00");
            Date endDate = format.parse(format1 + " 23:59:59");
            hashMap.put("beginDate", beginDate);
            hashMap.put("endDate", endDate);
        } catch (ParseException e) {
            e.printStackTrace();
            throw new BaseException("日期转换出错：" + e.getMessage());
        }
        return hashMap;
    }

    /**
     * 获取编码
     *
     * @Auth: 张恒
     */
    public static String getCode(Integer maxNum, String type, Date date) {
        String code = "";
        if (maxNum < 10) {
            code = "000" + maxNum.toString();
        } else if (maxNum >= 10 && maxNum < 100) {
            code = "00" + maxNum.toString();
        } else if (maxNum >= 100 && maxNum < 1000) {
            code = "0" + maxNum.toString();
        } else {
            code = maxNum.toString();
        }
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMM");
        String format2 = simpleDateFormat.format(date);
        return type + format2 + "-" + code;
    }


}
